<?php
/*
	页面链接
*/
$data=array(
		'nickname'=>trim($post['nickname']),
		'name'=>trim($post['name']),
		'picurl'=>trim($post['picurl']),
		'groupid'=>intval($post['groupid']),
		'type'=>intval($post['type']),
		'mpname'=>trim($post['mpname']),
		'number'=>trim($post['number']),
		'isadmin'=>intval($post['isadmin']),
		'showkfqr'=>trim($post['showkfqr']),
		'kefuqr'=>trim($post['kefuqr']),
		'paixu'=>intval($post['paixu']),
		'welcometext'=>trim($post['welcometext']),
		'fansauto'=>trim($post['fansauto']),
		'kefuauto'=>trim($post['kefuauto']),
		'autoset'=>intval($post['autoset']),
		'onlinetime'=>ijson_encode($post['onlinetime']),
		'offlinetext'=>trim($post['offlinetext']),
		'isonline'=>intval($post['isonline']),
		'isshow'=>intval($post['isshow']),
		'wxappid'=>intval($post['wxappid']),
		'mid'=>intval($post['mid']),
	);
	$id=intval($post['id']);
	$keyid=intval($post['keyid']);
	$type=intval($post['type']);
	if($type == 4 || $type == 5){
		$backdata=array(
				'title'=>'全网客服-'.$_SESSION['uniacid'],
				'backtype'=>8,
				'action'=>'wechat',
				'status'=>1,
				'keyword'=>'客服:'.trim($post['name']).'@'.$_SESSION['uniacid'],
				'key'=>$_SESSION['uniacid'].'name'.$post['name'],
		);
		if(empty($keyid)){
			$keyid = cfc('core')->save_back($backdata,'jy_kefu');
			$data['keyid']=$keyid;
		}
		if(empty($qrticket)){
			$title = '全网客服-客服：'.$post['name'].'de二维码';
			$getqrdata=array(
				'keyid'=>$keyid,
			);
			$getqrdata = ijson_encode($getqrdata);
			$qr = cfc('account')->get_qr(2,'jy_kefu',$getqrdata,30,$title);	
			$data['qrticket']=$qr['ticket'];
		}
	}
	if(empty($post['name'])){
		exi('请填写客服账号！','error');
	}
	$kf_account=trim($post['name']).'@'.trim($post['mpname']);
	$nickname=trim($post['nickname']);
	if($id){
		if($type == 4 || $type == 5){
			$content = cfc('kefu')->upkefuinfo($kf_account,$nickname);
			if($content['errcode'] == 65401){
				cfc('kefu')->setkefu($kf_account,$nickname);
			}elseif($content['errcode'] != 0){
				exi(cfc('kefu')->error_code($content['errcode']),'error');
			}
		}
		pdo_update('jy_kefus',$data,array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}else{
		if($type == 4 || $type == 5){
			cfc('kefu')->setkefu($kf_account,$nickname);
		}
		if(pdo_getcolumn('jy_kefus',array('name' => $post['name'],'uniacid'=>$_SESSION['uniacid']),'id')){
			exi('非常抱歉，此账号已被使用，你需要更换客服账号！','error');
		}
		$data['uniacid']=$_SESSION['uniacid'];
		$data['plugin']='jy_merch';
		$data['pid']=$merchid;
		pdo_insert('jy_kefus',$data);
	}
	
	exi('保存成功！','','list');